<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      html,
      body,
      #app {
        margin: 0;
        padding: 0;
      }
      #app {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
      }

      button {
        margin-bottom: 10px;
        width: 1.3333333333333333rem;
      }
    </style>
    <script>
      function remRefresh() {
        // 获取当前设备屏幕的宽度
        let clientWidth = document.documentElement.clientWidth;
        // 将屏幕分为10份
        let rem = clientWidth / 10;
        document.documentElement.style.fontSize = rem + 'px';
        document.body.style.fontSize = '12px';
      }

      window.addEventListener('pageshow', () => {
        remRefresh();
      });

      // 函数防抖
      let timeoutId;
      window.addEventListener('resize', () => {
        timeoutId && clearTimeout(timeoutId);
        timeoutId = setTimeout(() => {
          remRefresh();
        }, 300);
      });
    </script>
  </head>
  <body>
    <div id="app">
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
      <button>A</button>
    </div>
  </body>
</html>
